\documentclass[12pt]{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage{sidecap}
\usepackage{wrapfig}
\usepackage{fancyhdr}
\usepackage{amsmath}
\pagestyle{fancy}
\renewcommand{\baselinestretch}{1.2}
\newenvironment{mylisting}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting2}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting3}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting4}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting5}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\newenvironment{mylisting6}
{\begin{list}{}{\setlength{\leftmargin}{1em}}\item\scriptsize\bfseries}
{\end{list}}
\begin{document}
	\textbf{{\Huge Quark Gluon plasma Java/Ambienttalk/2 Computer Graphics supporting/system code}}
{\center{May 2, 2013, 
	Johan Ceuppens, Theo D'Hondt - Vrije Universiteit Brussel}}
\\

{\center{With thanks to : Ellie D'Hondt, the SOFT lab and the Open Source Community}}

{\large{\textbf{\center Abstract}}}
\\

	This is code which was developed for Java and Ambienttalk/2 systems to provide for computer graphics research. It is a mere illustration.


\section{ Java/Ambienttalk/2 support game code }

\begin{mylisting}
\begin{verbatim}
package game.johan.angelsdestiny;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import game.johan.engine.EngineBase;

import java.io.BufferedInputStream;
import java.io.FileInputStream;

import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Environment;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.graphics.Bitmap;
import android.view.SurfaceView;
import android.content.Context;

/*
 * There's a bridge to the EngineBase instance
 * to provide an example game
 */

public class AngelsDestinyBase extends EngineBase
{
	private int _w,_h;
static	EngineBase _base;//bridged
	
	public AngelsDestinyBase() {
		initAppWH(320,200);
		
		/*
		 * You can change this to setToSingleCore();
		 */
		setToMultiCore();
		
		_base = this;
	}
	
	public void initAppWH(int ww, int hh) {
		_w = ww;
		_h = hh;
		setscreenwh(_w,_h);
	}
 }
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

public class AIMachine 
{
	public byte _bytecodes[][];
	public AIMachine () {}

	public void update() {
		
		
	}
	
	public byte[] getCode(int id) {
		return (byte[])(_bytecodes[id]);
	}
	
	public int parseCode(int id) {
		byte[] code = getCode(id);
		int i = 0;
		
		//parses a series of ai codes as behaviour
		while (i < code.length) {
			switch(code[i]){
				case 0x1:
					doCode0x01();
					break;
				default:
					return -1;
			}
			i++;
		}
		
		return 0;
	}
	
	public void doCode0x01() {
		
	}
	
}package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
/*
 * This should become a bucket hashtable
 */

public class BitmapHashTable
{
	byte _bytearray[][];
	int _capacity1 = 0;
	int _capacity2 = 0;
	
	int markoffset = 0;
	int mark = 0;
	
	EngineBase _base;
	Canvas _canvas;
	
	public BitmapHashTable(int capacity1, int capacity2, Canvas canvas, EngineBase base) {
		
		_canvas = canvas;
		_base = base;
		
		_capacity1 = capacity1;
		_capacity2 = capacity2;
		_bytearray = new byte[capacity1][capacity2];
		
	}
	
	public void add(Canvas canvas, EngineBase base, Image b) {
/***FIXME		Surface surf = new Surface(b);
		//drawOnCanvasBaseBitmap(Bitmap b)
		int m = b.getWidth()*b.getHeight()+markoffset++;
		if (m > mark)
			mark = m; 
		if (m > _capacity1) {
			_capacity1 = m+1;
			int i = 0;
			byte ba[][] = new byte[_capacity1][_capacity2];
			while (i < _bytearray.length)
				ba[i] = _bytearray[i];
			_bytearray = ba;
		}
		if (surf.toByteArray().length > _capacity2)
			_bytearray[m] = new byte[surf.toByteArray().length+1];
		_bytearray[m] = surf.toByteArray();
*/	}
	
	public void add(Image b) {
		//Surface surf = new Surface(b);
		//drawOnCanvasBaseBitmap(Bitmap b)
		//_bytearray[b.getWidth()*b.getHeight() % markoffset++] = surf.toByteArray();
	}
	
/*	public byte[] get(Bitmap b) {
		return (_bytearray[b.getWidth()*b.getHeight() % markoffset]);
	}
*/
/*	
	public void drawOn(Surface surf) {
		int i = 0;
		for ( ; i < mark; i++) {
			byte[] bytes = _bytearray[i];
			if (bytes != null) {
				int bytesize = bytes.length;
				ByteBuffer bb = ByteBuffer.allocate(bytesize); 
				bb.put(bytes, 0, bytesize);
				surf.drawOnByteBuffer(s._surfacew,_surfaceh,bb);
			}
		}
	}
*/
}
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.util.ArrayList;
import java.util.List;

/*
 * This class can store surfacelist and surface objects
 * It can fetch the next surface from these inside 
 * the _buffer variable
 * 
 * Memento class inside
 */

class Caretaker<O>
{
	public class Memento<O>
	{
		private final O _o;
		public Memento(O o) {
			_o = o;
		}
		public O get() {
			return _o;
		}
	}
	
	List<Memento<O>> _saves = new ArrayList<Memento<O>>();
	O _save;
	
	public void save(O state) {
		_saves.add(new Memento<O>(state));
	}
	
	public void restore() {
		if (_saves.size() == 0)
			return;
		
		int l = _saves.size()-1;
		_save = (O)_saves.get(l);
		_saves.remove(l);
	}
	
}package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.nio.ByteBuffer;
import java.util.LinkedList;


public class DrawMethodList
{
	EngineBase _base;
	LinkedList _list = new LinkedList();
	
	private int _currentindex;
	
	private Caretaker<DrawMethodList> _drawmethodresourcecaretaker = new Caretaker<DrawMethodList>();
	
	public DrawMethodList(EngineBase base) {
		
		_base = base;
		
	}

	public int size() {
		return _list.size();
	}

	public void clear() {
		_list.clear();
	}	
	
	public void add(DrawMethod surf) {
		_list.add(surf);
	}
	
	public DrawMethod get(int idx) {
		return (DrawMethod)(_list.get(idx));
	}
	
	public DrawMethod get() {
		//reform _currentindex at end to begin of list
		if (_currentindex >= _list.size())
			_currentindex = 0;
		return (DrawMethod)(_list.get(_currentindex++));
	}
	
	public void save() {
		_drawmethodresourcecaretaker.save(this);
	}
	
	public void restore() {
		_drawmethodresourcecaretaker.restore();
	}
	
}
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

//FIXME 2 singletons for _canvas & _canvasThreand & Holders
public class EngineBase extends JPanel implements ActionListener
{
	private int _multicore = 2;//FIXME changes at runtime
	private GameObjectThread _drawthread;
	private GameObjectUpdateThread _updatethread;
	
	private GameThreadSingleCore _gamethreadsinglecore;

	private String fileprefixpics = "./pics/";	
	private Canvas _canvas;
	private int _screenw;
	private int _screenh;
	private Surface _screensurface;
	private SurfaceList _surfacelist;
	private DrawMethodList _drawmethodlist;
	private AIMachine _aimachine;

	private SurfaceTileMap _surfacetilemap = new SurfaceTileMap();
	private int _xmapoffset = 0;
	private int _ymapoffset = 0;
	public EngineBase() {
		
		_screenw = 640;
		_screenh = 480;
		_screensurface = new Surface(0,0,_screenw,_screenh);
			
		_surfacelist = new SurfaceList(this);
		_drawmethodlist = new DrawMethodList(this);	
		Timer timer;

        	addKeyListener(new EngineBaseAdapter());
        	setFocusable(true);
	
        	setBackground(Color.white);
        	setDoubleBuffered(true);

        	timer = new Timer(40, this);
        	timer.start();

	}

	/* NOTE that the offsets get transmogrified inside the surfacetile
	*/
    	class EngineBaseAdapter extends KeyAdapter {
        public void keyReleased(KeyEvent e) {
		_xmapoffset = 0;
		_ymapoffset = 0;
	} 
      

        public void keyPressed(KeyEvent e) {
          int key = e.getKeyCode();

	   	if (key == KeyEvent.VK_LEFT) {
			_xmapoffset -= 10;
		} else if (key == KeyEvent.VK_RIGHT) {
			_xmapoffset += 10;
		} else if (key == KeyEvent.VK_UP) {
			_ymapoffset -= 10;
		} else if (key == KeyEvent.VK_DOWN) {
			_ymapoffset += 10;
		}
		}
	};
    	public void actionPerformed(ActionEvent e) {
        	repaint();  
    	}

	//FIXME not at runtime
	public void setToSingleCore() {
		_multicore = 1;
	}
	
	public void setToMultiCore() {
		_multicore = 1;
	}
	
  public void start() {
	  
	  if (_multicore == 2) {
		  
	  /*
	   * async game event handler, with GameEvent instances for events
	   * This might be changed to multiple handlers for (multi-core) systems
	   */
      final GameObjectEventSource _draweventsource = new GameDrawEventSource(this);
      final GameEventHandler _draweventhandler = new GameDrawEventHandler();
      _draweventsource.addObserver(_draweventhandler);

      // starts the drawing event thread
      _drawthread = new GameObjectThread(this,_draweventsource);
      _drawthread.start();
      
      final GameObjectEventSource _updateeventsource = new GameDrawEventSource(this);
      final GameEventHandler _updateeventhandler = new GameDrawEventHandler();
      _updateeventsource.addObserver(_updateeventhandler);

      // starts the update event thread
      _updatethread = new GameObjectUpdateThread(this,_draweventsource);
      _updatethread.start();

	  } else {
		  
	  final GameEventSource _eventsource = new GameEventSource(/*this*/);
	      final GameEventHandler _eventhandler = new GameEventHandler();
	      _eventsource.addObserver(_eventhandler);

	      // starts the drawing event thread
	      _gamethreadsinglecore = new GameThreadSingleCore(this,_eventsource);
	      _gamethreadsinglecore.start();
		  
	  }
  }
  
  public void renderscreensurface() {
	  	_surfacelist.drawOn(_screensurface);
	  	_screensurface.render(this);
  }

  public void update() {
	  _aimachine.update();
  }
  
  public void end() {

	  if (_multicore == 2) {
	  
	  boolean retry = true;
	  _drawthread.setRunning(false);
	  _updatethread.setRunning(false);
	  while(retry) {
	  try {
		  _drawthread.join();
		  _updatethread.join();
		  retry = false;
	  	} catch (InterruptedException e) {
	    	System.out.println("Message "+e.getMessage());
	    	e.printStackTrace();
	  	}
	  }
	  } else {
		  boolean retry = true;
		  _gamethreadsinglecore.setRunning(false);
		  while(retry) {
		  try {
			  _gamethreadsinglecore.join();
			  retry = false;
		  	} catch (InterruptedException e) {
		    	System.out.println("Message "+e.getMessage());
		    	e.printStackTrace();
		  	}
		  }  
		  
		  
	  }
  }
  /** Called when the activity is first created. */
//  @Override
//  public void onCreate(Bundle savedInstanceState) {
//      super.onCreate(savedInstanceState);
//      setContentView(R.layout.main);
//      ImageView image = (ImageView) findViewById(R.id.test_image);
//      Bitmap bMap = BitmapFactory.decodeFile("/sdcard/test2.png");
//      image.setImageBitmap(bMap);
//  }

  public void paint(Graphics g)
    {
      	Graphics2D g2d = (Graphics2D) g;
      	g2d.setColor(Color.black);
      	g2d.fillRect(0, 0, 640, 480);
	//render screensurface
	renderscreensurface();

	//NOTE surfaces only render before the next loop of the _drawmethodslist
//example code
//	ImageTile t0 = new ImageTile0("t16tiles.png");//320x853
//	g2d.drawImage(t0.get(),0,0,this);
//	SurfaceTile st0 = new SurfaceTile("stub.png",100,0,64,64);
//	Surface s0 = st0.get();
//	s0.setRegion(0,0,48,48);
//	s0.render(this);

	while (true) { 
		SurfaceTile surftile = _surfacetilemap.get();
		if (surftile == null)
			break;
		else {
			if (_xmapoffset != 0 || _ymapoffset != 0)
				surftile.setxy(surftile.getx()+_xmapoffset,surftile.gety()+_ymapoffset);
			surftile.get().render(this);
		}
	} 

	//Image img = new ImageIcon(fileprefixpics+"t16tiles.png").getImage();
	//g2d.drawImage(img,0,0,this);	
	//draw 
	int idx = 0;
	for ( ; idx < _drawmethodlist.size(); idx++ )
		_drawmethodlist.get(idx).draw(g2d, this);
	_drawmethodlist.clear();

  	Toolkit.getDefaultToolkit().sync();
      	g2d.dispose();
    } 

  protected void drawOnPanel(DrawMethod dm) {
	//done before df.init();
	//_drawmethods.add(df.f(g2d,img,0,0,this));
	_drawmethodlist.add(dm);
  }
  
  public void setscreenwh(int w, int h) {
	  _screenh = h;
	  _screenw = w;
  }
 }
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

/*
* make extensions for modding bufferedimages
*/
abstract class DrawMethod {
	BufferedImage i = null;
	int x = 0,y = 0;
	public void init(int xx, int yy, BufferedImage img) {};
	public void draw(Graphics2D g2d, JPanel jp) {};
} 
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.util.Observable;
import java.util.Observer;  /* this is Event Handler */
 
public class GameDrawEventHandler extends GameObjectEventHandler {
    private GameDrawEvent resp;//OR String
    public void update(Observable obj, Object arg) {
    	if (arg instanceof GameEvent) {
            resp = (GameDrawEvent) arg;
            System.out.println("\nReceived Game (Object) Draw Event Response: "/* + resp.getStringCode() */);
        }
    }
}package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
public class GameDrawEvent extends GameObjectEvent {

	public GameDrawEvent() {
	}
	
    public String toString() {
    	return "GameDrawEvent";
    }
}
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.util.Observable;          //Observable is here
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class GameDrawEventSource extends GameObjectEventSource {
	
	EngineBase _base;
	public GameDrawEventSource(EngineBase base) {
		_base = base;
	}
	
    public void run() {
        try {
            while (true) {
/*FIXME                GameDrawEvent response = _base.pollDraw();//FIXME poll multiple or perfect match
                setChanged();
                notifyObservers(response);
*/            }
        } catch (Exception e) {
        	System.out.println("Message "+e.getMessage());
        	e.printStackTrace();
        }
    }
}
package game.johan.engine;


/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
public class GameDrawThread extends GameObjectThread {
	
	public GameDrawThread(EngineBase base, GameDrawEventSource gamedrawevent) {
		super(base, gamedrawevent);
	}

	private boolean running;
	 public void setRunning(boolean running) {
		 this.running = running;
	 }
	
	@Override
	 public void run() {
		  while (running) {
		   try {
		     // draws the canvas
//FIXME		     _base.render(/*canvas*/);
		   } finally {
			   this.destroy();//release
		   }
		  }
		 }
}
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.util.Observable;
import java.util.Observer;  /* this is Event Handler */
 
public class GameEventHandler implements Observer {
    private GameEvent resp;//OR String
    public void update(Observable obj, Object arg) {
    	if (arg instanceof GameEvent) {
            resp = (GameEvent) arg;
            System.out.println("\nReceived Game Event Response: "/* + resp.getStringCode() */);
        }
    }
}package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
public class GameEvent {
	
//	EngineBase _base;
	public GameEvent(/*EngineBase base*/) {
//		_base = base;
	}
	
    public String toString() {
    	return "GameEvent";
    }
}
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.util.Observable;          //Observable is here
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class GameEventSource extends Observable implements Runnable {
	
	public GameEventSource() {
	}
	
    public void run() {
    }
}
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.util.Observable;
import java.util.Observer;  /* this is Event Handler */
 
public class GameObjectEventHandler extends GameEventHandler {
    private GameObjectEvent resp;//OR String
    public void update(Observable obj, Object arg) {
    	if (arg instanceof GameEvent) {
            resp = (GameObjectEvent) arg;
            System.out.println("\nReceived Game Object Event Response: "/* + resp.getStringCode() */);
        }
    }
}package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
 
public class GameObjectEvent extends GameEvent {
	
	public GameObjectEvent() {
	}
	
    public String toString() {
    	return "GameObjectEvent";
    }
}
package game.johan.engine;
 
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.util.Observable;          //Observable is here
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class GameObjectEventSource extends GameEventSource {
	
	public GameObjectEventSource() {
	}
	
    public void run() {
    }
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

public class GameObject
{
	
	public GameObject() {}
	
}
package game.johan.engine;


/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
public class GameObjectThread extends Thread {
	
	EngineBase _base;
	
	public GameObjectThread(EngineBase base, GameEventSource gameEventSource) {
		super(gameEventSource);
		_base = base;
	}

	public void setRunning(boolean running) {
	}
	
	 public void run() {}

}
package game.johan.engine;


/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
public class GameObjectUpdateThread extends GameObjectThread {
	
	public GameObjectUpdateThread(EngineBase base, GameObjectEventSource gameeventsource) {
		super(base, gameeventsource);
	}
	private boolean running = true;
	public void setRunning(boolean running) {
		 this.running = running;
	 }
	
	@Override
	 public void run() {
		  while (running) {
		   try {
		     //update game state
			   _base.update();//is in other thread
		     
		   } finally {
			   this.destroy();//release
		   }
		  }
		 }
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

public class GameSurfaceObject extends GameObject
{
	private Surface _surface;
	
	public GameSurfaceObject(Surface surf) {
		
		_surface = surf;
	}
	
}package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
public class GameThread extends Thread {

	EngineBase _base;
	
	public GameThread(EngineBase base, GameEventSource gameEventSource) {
		super(gameEventSource);
		_base = base;
	}
	 
	 @Override
	 public void run() {}

}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
public class GameThreadSingleCore extends Thread {

	EngineBase _base;
	
	public GameThreadSingleCore(EngineBase base, GameEventSource gameEventSource) {
		super(gameEventSource);
		_base = base;
	}
	 
	private boolean running = true;
	public void setRunning(boolean running) {
		 this.running = running;
	 }
	
	@Override
	 public void run() {
		
		while (running) {
		   try {
/***FIXME		     // draws the canvas
		     _base.render();
		     //update game state
			 _base.update();
***/		   } finally {
			   this.destroy();//release
		   }
		  }
	 }

}
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.ByteArrayOutputStream;

class GraphicsUtility {

/* Create an ARGB BufferedImage */
/*BufferedImage img = ImageIO.read(imageSrc);
int w = img.getWidth(null);
int h = img.getHeight(null);
BufferedImage bi = new
    BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.getGraphics();
g.drawImage(img, 0, 0, null);
*/
/*
 * Create a rescale filter op that makes the image
 * 50% opaque.
 */
/*float[] scales = { 1f, 1f, 1f, 0.5f };
float[] offsets = new float[4];
RescaleOp rop = new RescaleOp(scales, offsets, null);
*/
/* Draw the image, applying the filter */
/*g2d.drawImage(bi, rop, 0, 0);
*/
/***

boolean Graphics.drawImage(Image img,
                   int x, int y,
                   ImageObserver observer);
 The observer parameter is not frequently used directly and is not needed for the BufferedImage class, so it usually is null.

boolean Graphics.drawImage(Image img,
       int dstx1, int dsty1, int dstx2, int dsty2,
       int srcx1, int srcy1, int srcx2, int srcy2,
       ImageObserver observer);
*/
/* divide the image 'bi' into four rectangular
 * areas and draw each of these areas in to a
 * different part of the image, so as to jumble
 * up the image.  'cells' is an array which has
 * been populated with values which redirect
 * drawing of one subarea to another subarea.
 */
/*int cellWidth = bi.getWidth(null)/2;
int cellHeight = bi.getHeight(null)/2;
for (int x=0; x<2; x++) {
    int sx = x*cellWidth;
    for (int y=0; y<2; y++) {
        int sy = y*cellHeight;
        int cell = cells[x*2+y];
        int dx = (cell / 2) * cellWidth;
        int dy = (cell % 2) * cellHeight;
        g.drawImage(bi,
                    dx, dy, 
                    x+cellWidth, dy+cellHeight,
                    sx, sy,
                    sx+cellWidth, sy+cellHeight,
                    null);
    }
}
void Graphics2D.drawImage(BufferedImage img,
                          BufferedImageOp op,
                          int x, int y)







*/

/***
try {
    // retrieve image
    BufferedImage bi = getMyImage();
    File outputfile = new File("saved.png");
    ImageIO.write(bi, "png", outputfile);
} catch (IOException e) {
    ...
}

***/
/*
BufferedImage off_Image =
  new BufferedImage(100, 50,
                    BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = off_Image.createGraphics();
*/

/*Object methodCaller(Object theObject, String methodName) {
   return theObject.getClass().getMethod(methodName).invoke(theObject);
   // Catch the exceptions
}
 */
	
public void encode1() {
/*	Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.images);
	ByteArrayOutputStream stream=new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
    byte[] image=stream.toByteArray();
    System.out.println("byte array:"+image);

    String img_str = Base64.encodeToString(image, 0);
    System.out.println("string:"+img_str);
*/
}

public void initcanvasbmp() {
	/*Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
	scrbitmap = Bitmap.createBitmap(320, 200, conf); // this creates a MUTABLE bitmap
	canvas = new Canvas(scrbitmap);
	 */
	}
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

class ImageTileBase<T> extends Tile<String>
{
	protected String fileprefix = "./pics/";
	protected T _image;
	public T getImage() {  
		return _image;
	}
	public T get() {  
		return _image;
	}
}

package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

class ImageTile extends ImageTileBase<Image> 
{
	public ImageTile(String gfxfilename)	{
		_image = new ImageIcon(fileprefix+gfxfilename).getImage();
		_tilesdict.addCreator(this);
	}
}

package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

public class PlayerBase extends GameObject
{
	
	public PlayerBase() {}
	
}package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import game.johan.engine.SurfaceFetcher.ImageR;

import java.util.LinkedList;

/*
 * This class can store surfacelist and surface objects
 * It can fetch the next surface from these inside 
 * the _buffer variable
 */

class SurfaceFetcher
{
	class ImageR {
		//FIXME image
		public ImageR(/*image*/) {
			
		}
	}
	
	private int _currentindex; 
	private LinkedList _buffer = new LinkedList();
	public SurfaceFetcher() {
		_currentindex = 0;
	}
	
	public Surface get() {
		if (_currentindex < _buffer.size()) {
			Object o = _buffer.get(_currentindex);
			if (o instanceof SurfaceList) {
				SurfaceList surflist = ((SurfaceList)o);
				Surface surf = (Surface)surflist.get();
				if (surflist.isLast()) {
					_currentindex++;
				}
				return surf;
			} else {
				_currentindex++;
				return (Surface)o;
			}

		}
		return null;
	}
	
	public void put(Surface surf) {
		_buffer.add(surf);
	}
	
	public void put(SurfaceList surflist) {
		_buffer.add(surflist);
	}
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
/*
 *  This class provides a bitmap surface and a
 *  ByteBuffer, you can render it and draw bytebuffers
 *  and bitmaps on it
 * 
 *  The Bytebuffer _bb gets bitmapped on _canvas with draawbbOn,
 *
 *  The bitmap can be written on with drawOn methods
 */
class Surface
{
private BufferedImage _image;
private ByteBuffer _bb,_loadbb;
private Caretaker<String> _fileresourcecaretaker = new Caretaker<String>();

private int _surfacew = 0;
private int _surfaceh = 0;
private int _surfacex = 0;
private int _surfacey = 0;
private String fileprefixpics = "./pics/";

public Surface(int x, int y, int w, int h) {
	_surfacex = x;
	_surfacey = y;
	_surfacew = w;
	_surfaceh = h;
	init();
}

public Surface(int x, int y, int w, int h, BufferedImage b) {
	_surfacex = x;
	_surfacey = y;
	_surfacew = w;
	_surfaceh = h;
	initWithImage(b);
}

private ByteBuffer init() {
 // open image
try {
 File path = new File(fileprefixpics+"stub.png");
 _image = ImageIO.read(path);
_bb = ByteBuffer.allocate(_surfacew * _surfaceh * 4);
} catch (IOException e) {
	System.out.println("Message "+e.getMessage());
	e.printStackTrace();
}
 // get DataBufferBytes from Raster
 WritableRaster raster = _image.getRaster();
 DataBufferByte data   = (DataBufferByte) raster.getDataBuffer();

 byte[] bb = data.getData();
// _bb.put(bb,0,bb.length);

 return _bb;

}


private ByteBuffer initWithImage(BufferedImage img) {
    _image = img;
 // get DataBufferBytes from Raster
 WritableRaster raster = _image.getRaster();
 DataBufferByte data   = (DataBufferByte) raster.getDataBuffer();

_bb = ByteBuffer.allocate(_surfacew * _surfaceh * 4);

 byte[] bb = data.getData();
 _bb.put(bb,0,bb.length);

    return _bb;

}

public int getsurfacew() {
	return _surfacew;
}

public int getsurfaceh() {
	return _surfaceh;
}

public int getsurfacex() {
	return _surfacex;
}

public int getsurfacey() {
	return _surfacey;
}

public void draw(EngineBase base) {
	render(base);
}

public void render(EngineBase base) {
  synchronized (this) {
    try {

	class DrawMethodR extends
	DrawMethod {
        public void init(BufferedImage img, int xx, int yy) {
                x = xx; y = yy; i = img; 
	}
        public void draw(Graphics2D g2d, JPanel jp) {
		g2d.drawImage((BufferedImage)i, null, x, y);
	}
        };

	DrawMethodR dm = new DrawMethodR();
	dm.init(_image, _surfacex, _surfacey);
    	base.drawOnPanel(dm);

    } catch (Exception e) {
    	System.out.println("Message "+e.getMessage());
    	e.printStackTrace();
    }
  }
}

public void drawbbOn() {
/***
	BufferedImage originalImage = ImageIO.read(new File(
					"c:/darksouls.jpg"));
	// convert BufferedImage to byte array
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	ImageIO.write(originalImage, "jpg", baos);
	baos.flush();
	_bb = baos.toByteArray();
	baos.close();
***/
try {
	// convert byte array back to BufferedImage
	byte[] bytes = new byte[toImageSurface()];
	_bb.get(bytes, 0, bytes.length);
	InputStream in = new ByteArrayInputStream(bytes);
//	BufferedImage bImageFromConvert = ImageIO.read(in);
	_image = ImageIO.read(in);
//	ImageIO.write(bImageFromConvert, "jpg", new File(
//					"c:/new-darksouls.jpg"));
    } catch (Exception e) {
    	System.out.println("Message "+e.getMessage());
    	e.printStackTrace();
    }
}

public void drawloadbbOn() {
try {
	byte[] bytes = new byte[toImageSurface()];
	_loadbb.get(bytes, 0, bytes.length);
	InputStream in = new ByteArrayInputStream(bytes);
	_image = ImageIO.read(in);
    } catch (Exception e) {
    	System.out.println("Message "+e.getMessage());
    	e.printStackTrace();
    }
}

private void release() {
    _image = null;
    _bb = null;
    //_loadbb = null;
}


public byte[] toByteArray() {
	byte[] bytes = new byte[toImageSurface()];
	//try {
	    _bb.get(bytes, 0, bytes.length);
	//}
	//catch (BufferUnderflowException e)
	//{
    	//System.out.println("Message "+e.getMessage());
    	//e.printStackTrace();
	//}
	return bytes;
	//do something with bytes
}

public byte[] toArray2() {
	byte[] bytes = new byte[toImageSurface()];
	return bytes;
	//do something with bytes
}

public int toImageSurface() {
	//int size = _image.getRowBytes() * _image.getHeight();
	int size = _surfacew * _surfaceh * 4;
	_bb = ByteBuffer.allocate(size);
//FIXME	_image.copyPixelsToBuffer(_bb);
	return size;
}

/*
 * ww,hh is width and height of bb arg
 */
public void drawOnByteBuffer(int ww, int hh, ByteBuffer bb) {
	int sizew = _surfacew;//_image.width;
	int i = 0, j = 0, kw = 0;
	for ( ; i < hh; i++) {
		for( ; j < ww; j++) {
			_bb.put(kw,bb.get(i*ww+j));
			kw++;
		}
		kw += sizew-ww;
		j = 0;
	}
}
	
public void toByteBuffer(byte[] ba) {
	int ww = _surfacew;
	int hh = _surfaceh;
	int sizew = _surfacew;//FIXME!
	int i = 0, j = 0, kw = 0;
	for ( ; i < hh; i++) {
		for( ; j < ww; j++) {
			_bb.get(ba, 0, ba.length);
			kw++;
		}
		kw += sizew-ww;
		j = 0;
	}
}
	
/*
 * This draws the byte[] ba on the _image surface with offsets xx,yy and
 * width and height ww,hh.
 * The bitmap can be loaded with the load() method
 * and provide a background surface
 */
public void drawOnByteArray(int xx, int yy, int ww, int hh, byte[] ba) {
	toByteBuffer(ba);
	drawOnByteBufferxy(xx,yy,ww,hh,_bb);
	//done above _image.copyPixelsFromBuffer(_bb);			
}
	
/*
 * The following method write the bytebuffer after load()
 * over the surface _image
 * There also is a loadanddraw method in this file
 */
public void drawOnLoadByteBuffer(int xx, int yy, int ww, int hh) {
	drawOnByteBufferxy(xx,yy,ww,hh,_loadbb);
	//done above _image.copyPixelsFromBuffer(_bb);			
}

/*
 * ww,hh is width and height of bb arg
 * xx,yy is position of in bb stored image to draw on _bb
 */
public void drawOnByteBufferxy(int xx, int yy, int ww, int hh, ByteBuffer bb) {
	int sizew = _surfacew;
	//int sizeh = _image.getHeight();
	int i = 0, j = 0, kw = xx+yy*ww;
	for ( ; i < hh; i++) {
		for( ; j < ww; j++) {
			_bb.put(kw,bb.get(i*ww+j));
			kw++;
		}
		kw += sizew-ww;
		j = 0;
	}
	
	
}

/*
 * set the _image to a region of the _image
 */
public void setRegion(int regx, int regy, int regw, int regh)
{
 	WritableRaster raster = _image.getRaster();
 	DataBufferByte data   = (DataBufferByte) raster.getDataBuffer();

 	byte[] srcbytes = data.getData();
	int size = regw * regh * 3;

	byte[] destbytes = new byte[size];
	int sizew = _surfacew*3;
	int i = 0, j = 0, kw = 0;
	for ( ; i < regh; i++) {
		for( ; j < regw*3; j+=3) {
			destbytes[i*regw*3+j] = srcbytes[kw];
			destbytes[i*regw*3+j+1] = srcbytes[kw+1];
			destbytes[i*regw*3+j+2] = srcbytes[kw+2];
			kw+=3;
		}
		kw += sizew-regw*3;
		j = 0;
	}
    try {
	InputStream in = new ByteArrayInputStream(destbytes);
	_image = ImageIO.read(in);
    } catch (Exception e) {
    	System.out.println("Message "+e.getMessage());
    	e.printStackTrace();
    }
		
	//drawbbOn();
}
/*
 * The following method provides a seperate bytebuffer _loadbb
 * which can be overwritten on the main _image surface
 * with the drawOnByteBufferxy method (bb as an ByteBuffer argument)
 */

public void load(String gfxfilename)
{

	if (_loadbb != null)
		return;
	
	try {
		if (gfxfilename == "") { 
			Image image = ImageIO.read(new File(fileprefixpics+"stub.png"));
			_image = (BufferedImage) image;
		} else {
			Image image = ImageIO.read(new File(fileprefixpics+gfxfilename));
			_image = (BufferedImage) image;
		}
	} catch (Exception e) {
    		System.out.println("Message "+e.getMessage());
    		e.printStackTrace();
	}
}

public void reload(String gfxfilename)
{
	try {
		if (gfxfilename == "") { 
			Image image = ImageIO.read(new File(fileprefixpics+"stub.png"));
			_image = (BufferedImage) image;
		} else {
			Image image = ImageIO.read(new File(fileprefixpics+gfxfilename));
			_image = (BufferedImage) image;
		}
	} catch (Exception e) {
    	System.out.println("Message "+e.getMessage());
    	e.printStackTrace();
	}
}

public void loadAndDraw(String gfxfilename, int xx, int yy, int ww, int hh)
{
	load(gfxfilename);
	_fileresourcecaretaker.save(gfxfilename);
	drawOnLoadByteBuffer(xx,yy,ww,hh);
}

public void reloadAndDraw(String gfxfilename, int xx, int yy, int ww, int hh)
{
	reload(gfxfilename);
	_fileresourcecaretaker.save(gfxfilename);
	drawOnLoadByteBuffer(xx,yy,ww,hh);
}

public void setxy(int xx,int yy) {
	_surfacex = xx;
	_surfacey = yy;
}

public int getx() { return _surfacex; }
public int gety() { return _surfacey; }
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


import java.nio.ByteBuffer;
import java.util.LinkedList;


public class SurfaceList
{
	EngineBase _base;
	LinkedList _list = new LinkedList();
	
	private int _currentindex;
	
	private Caretaker<SurfaceList> _surfaceresourcecaretaker = new Caretaker<SurfaceList>();
	
	public SurfaceList(EngineBase base) {
		
		_base = base;
		
	}
	
	public void add(Surface surf) {
		_list.add(surf);
	}
	
	public Surface get(int idx) {
		return (Surface)(_list.get(idx));
	}
	
	public Surface get() {
		//reform _currentindex at end to begin of list
		if (_currentindex >= _list.size())
			_currentindex = 0;
		return (Surface)(_list.get(_currentindex++));
	}
	
	public void save() {
		_surfaceresourcecaretaker.save(this);
	}
	
	public void restore() {
		_surfaceresourcecaretaker.restore();
	}
	
	public boolean isLast() {
		if (_currentindex == 0)
			return true;
		else
			return false;
	}
		
	public void drawOn(Surface destsurf) {
		int i = 0;
		for ( ; i < _list.size(); i++) {
			Surface s = (Surface)_list.get(i);
			byte[] bytes = s.toArray2();
			if (bytes != null) {
				int bytesize = bytes.length;
				ByteBuffer bb = ByteBuffer.allocate(bytesize); 
				bb.put(bytes, 0, bytesize);
				destsurf.drawOnByteBuffer(s.getsurfacew(), s.getsurfaceh(), bb);
			}
		}
	}
}
package game.johan.engine;
/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.util.LinkedList;

/*
 * This class can store surfacelist and surface objects
 * It can fetch the next surface from these inside 
 * the _buffer variable
 */

class SurfaceTileFetcher
{
	private Caretaker<SurfaceTileFetcher> _surfacetilefetchercaretaker = new Caretaker<SurfaceTileFetcher>();
	
	private int _currentindex; 
	private LinkedList _buffer = new LinkedList();
	public SurfaceTileFetcher() {
		_currentindex = 0;
	}

	public int size() {
		return _buffer.size();
	}
	
	public SurfaceTile get() {
		if (_currentindex < _buffer.size()) {
			Object o = _buffer.get(_currentindex);
				_currentindex++;
				return (SurfaceTile)o;
		} else {
			_currentindex = 0;
			return null;
		}
	}
	
	public void put(SurfaceTile surf) {
		_buffer.add(surf);
	}
	
	public void save() {
		_surfacetilefetchercaretaker.save(this);
	}
	
	public void restore() {
		_surfacetilefetchercaretaker.restore();
	}
	
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;


class SurfaceTile extends ImageTileBase<Surface>
{
	
	public SurfaceTile(String gfxfilename, int x, int y, int w, int h) {
		_image = new Surface(x,y,w,h); 
		_image.load(gfxfilename);
		_tilesdict.addCreator(this); 
	}

	public void setxy(int xx, int yy) {
		_image.setxy(xx,yy);
	}
	public int getx() { return _image.getx(); }
	public int gety() { return _image.gety(); }

}



package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.util.Random;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

class SurfaceTileMap
{
	private int _tilew = 16, _tileh = 16;

	SurfaceTileFetcher _surfacetilefetcher = new SurfaceTileFetcher();

	public SurfaceTileMap() {
		int x = 0, y = 0;
		for ( ; y < 10*_tileh; y+=_tileh) {
			for ( ; x < 10*_tilew; x+=_tilew) {
				SurfaceTile tilegrass1 = new SurfaceTile("tilegrass1-16x16.png", x,y,_tilew,_tileh);
				SurfaceTile tilegrass2 = new SurfaceTile("tilegrass2-16x16.png", x,y,_tilew,_tileh);
				Random r = new Random();
				if (r.nextInt(3) == 0)
					_surfacetilefetcher.put(tilegrass2);
				else
					_surfacetilefetcher.put(tilegrass1);
		//Tile._tilesdict.lookup("SurfaceTile0"); 	
			}
			x = 0;
		}
	}

	public int size() {
		return _surfacetilefetcher.size();
	}

	public SurfaceTile get() {
		return _surfacetilefetcher.get();
	} 

}


package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import java.lang.*;
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import java.util.HashMap;

class TileDictionary
{
static	HashMap<String,Tile> _dict = new HashMap<String,Tile>();

	public TileDictionary() {}
	public Tile<String> createFor(String tid) { Tile t = lookup(tid); return t; }
	public Tile<String> lookup(String tid)	{ return _dict.get(tid); }

	public void addCreator(Tile t) { /*FIXME use typeinfo */ String ti = t.getClass().toString(); _dict.put(ti, t); }
}
package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

class Tile<tid>
{

	/*
 	 * Creator of Tiles template subclass
	 */
	abstract class Creator<Return,Value>
	{
	private Value id;

	public Creator(Value v) {
		id = v;
	}

	public Value getid() { return id; }

	abstract Return create();
	};
	
	/*
 	 * TileCreator template subclass
	 */
	abstract class TileCreatorBase<Type,Return,Value> extends Creator<Return,Value>
	{
		TileCreatorBase(Value id) { super(id); }
		abstract Return create();//return new Type()
	};
	public class TileCreator extends TileCreatorBase<Object,Tile,Id>
	{
		TileCreator(Id id) { super(id); }
		public Tile create() { return new Tile<Id>(); }//FIXMENOTE return new Type()
	};


	/*
	 * Id class
	 */
	abstract class Id<tid>
	{	
	abstract tid getId();//FIXMENOTE TypeInfo class, getTypeName() (returns String) 
	public void init(tid c) { this.adaptTo(c); }
	abstract void adaptTo(tid c);
	abstract boolean matches(Id<tid> i);	
	};

	public Tile()	{}

	static TileDictionary _tilesdict = new TileDictionary();
}


package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.awt.*;
import javax.swing.*;

import java.awt.*;
import javax.swing.*;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

/* do not use, use the SurfaceTile and ImageTile classes */
class ImageTile0 extends ImageTile 
{
	public ImageTile0(String gfxfilename)	{
		super(gfxfilename);
	}
}

class SurfaceTile0 extends SurfaceTile
{
	public SurfaceTile0(String gfxfilename, int x, int y, int w, int h)	{
		super(gfxfilename,x,y,w,h);
	}
}



package game.johan.engine;

/*
Copyright (C) 2013 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

public class Tuple
{
	private Object _first,_second;
	
	public Tuple(Object o1, Object o2) {
		_first = o1;
		_second = o2;
	}
	
	public Object first() {
		return _first;
	}
	public Object second() {
		return _second;
	}
}package game.johan.wizardrpg; 
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import javax.swing.JFrame;
import game.johan.engine.*;
//TODO, improve this
public class WizardFrame extends JFrame
{
  private JFrame _frame;

  public WizardFrame()
  {
    new JFrame();
    getContentPane().add(new EngineBase());
    setTitle("Wizard RPG");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(640, 480);
    setLocationRelativeTo(null);
    setVisible(true);

    _frame = this;
  }

}
package game.johan.wizardrpg; 
/*
Copyright (C) 2012 Johan Ceuppens

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

import javax.swing.JFrame;
import game.johan.engine.*;

public class WizardRPG
{

  public WizardRPG()
  {
	WizardFrame jf = new WizardFrame();
  }

  public static void main(String[] args) {
      new WizardRPG();
  }
}

\end{verbatim}
\end{mylisting}


\section{\large Conclusion}


\bibliographystyle{plain}
\bibliography{plasmascreen} % refs.bib

\end{document}

%%



